# -*- coding: utf-8 -*-
from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms.dm.dm_employee_operate_num_detail import dm__dm_employee_operate_num_detail
from jms.time_sensor.time_after_05_45 import time_after_05_45
#jms.dm.员工信息
#jms_dm几种操作的单号
#组内员工操作单号
#组内员工操作量统计

jms_dm__dm_employee_operate_billcode_detail_out_dt = SparkSqlOperator(
    task_id='jms_dm__dm_employee_operate_billcode_detail_out_dt',
    email=['guoruiling@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_employee_operate_billcode_detail_out_dt_{{ execution_date | date_add(1) | cst_ds }}',
    pool_slots=4,
    # sla=timedelta(hours=7),
    driver_memory='8G',
    executor_memory='8G',
    executor_cores=6,
    num_executors=8,
    sql='jms/dm/dm_employee_operate_billcode_detail_out_dt/execute.hql',
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 16,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '4G',  # 堆外内存
          'spark.default.parallelism': 300,
          'spark.sql.shuffle.partitions': 280,
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=4',
          'spark.shuffle.consolidateFiles':'true',
          'spark.driver.extraJavaOptions': '-XX:+UseG1GC',
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions.pernode': 200,
              'hive.exec.max.dynamic.partitions': 200
              },
    execution_timeout = timedelta(minutes=30),
)
jms_dm__dm_employee_operate_billcode_detail_out_dt << [
    dm__dm_employee_operate_num_detail
    ,time_after_05_45
]